package stsj.meddroid;

import android.os.Bundle;
import android.view.KeyEvent;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.backends.android.AndroidApplication;
import com.badlogic.gdx.backends.android.surfaceview.GLBaseSurfaceView;

public class Starter extends AndroidApplication {
    /** Called when the activity is first created. */
	
	MainAppListener mainApp ;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);      

        
        
        
        MainAppListener mainAppTemp = (MainAppListener) getLastNonConfigurationInstance();
        
//        if (mainAppTemp !=null){
//        	mainApp = mainAppTemp;
//        }else{
        	mainApp = new MainAppListener(getApplicationContext()); 
//        }
    	
        initialize(mainApp, true);
        
//        View view = initializeForView(mainApp, new AndroidApplicationConfiguration());
//        setContentView(view);
        
        Thread concurrentGC = new Thread(new Runnable(){

			@Override
			public void run() {
				// TODO Auto-generated method stub
				while (true){
					try {
						Thread.sleep(20000);
						System.gc();
						Gdx.app.log("concurrentGC", "GC");
					} catch (InterruptedException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
					
					
					
				}
			}
        	
        });
//        concurrentGC.start();
//        KeyguardManager keyguardManager = (KeyguardManager)getSystemService(Activity.KEYGUARD_SERVICE);
//        KeyguardLock lock = keyguardManager.newKeyguardLock(KEYGUARD_SERVICE);
//        lock.disableKeyguard();

        
        
    }
    
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
    	// TODO Auto-generated method stub
    	if (keyCode == KeyEvent.KEYCODE_BACK){
//    		Gdx.app.log("BUTTT BACK", "DOWN");
    		return false;
    	}
    	return super.onKeyDown(keyCode, event);
    }
    
    @Override
    public boolean onKeyUp(int keyCode, KeyEvent event) {
    	// TODO Auto-generated method stub
    	if (keyCode == KeyEvent.KEYCODE_BACK){
//    		Gdx.app.log("BUTTT BACK", "UP");
    		return false;
    	}
    	return super.onKeyUp(keyCode, event);
    	
    	
    }
    
//    
//    @Override
//    protected void onPause() {
//    	// TODO Auto-generated method stub
//    	super.onPause();
////    	Gdx.app.log("ACTIVITY PAUSE", "===================");
//    	
//    	
//    }
//    
//    @Override
//    protected void onRestart() {
//    	// TODO Auto-generated method stub
//    	super.onRestart();
////    	Gdx.app.log("ACTIVITY RESTART", "===================");
//    }
//    
//    @Override
//    protected void onDestroy() {
//    	// TODO Auto-generated method stub
//    	super.onDestroy();
////    	Gdx.app.log("ACTIVITY DESTROY", "===================");
//    }
//    
//    @Override
//    protected void onStart() {
//    	// TODO Auto-generated method stub
//    	super.onStart();
////    	Gdx.app.log("ACTIVITY START", "===================");
//    }
//    
//    @Override
//    protected void onStop() {
//    	// TODO Auto-generated method stub
//    	super.onStop();
////    	Gdx.app.log("ACTIVITY STOP", "===================");
//    }
//    
//    @Override
//    protected void onResume() {
//    	// TODO Auto-generated method stub
//    	super.onResume();
////    	Gdx.app.log("ACTIVITY RESUME", "===================");
//    	
//    	
//    }
     @Override
    public Object onRetainNonConfigurationInstance() {
    	// TODO Auto-generated method stub
    	return mainApp;
    }
    
     
    
}